package com.gqz.jbox2d

import org.jbox2d.collision.AABB
import org.jbox2d.common.Vec2
import org.jbox2d.dynamics.BodyDef
import org.jbox2d.dynamics.World


/**
 * Descraption
 *
 * @author gqz
 * @data 2020/4/20
 */
class JBoxImpl {

    var world: World? = null
    var dt = 1f / 60f
    var velocityIteration = 5
    var positionIteration = 20
    var width = 0f
    var height = 0f
    var density = 0.5f
    var ratio = 50f

    fun createWorld() {
        if (world == null) {
            world = World(Vec2(0f, 10.0f))
            world!!.step(dt,velocityIteration,positionIteration)
        }
        world!!.createBody(createBodyDef())
    }

    fun startWorld() {
        world?.step(dt, velocityIteration, positionIteration)
    }

    fun createAABB(){
        var aabb = AABB()
        aabb.lowerBound.set(10f,10f)
        aabb.upperBound.set(100f,100f)
    }

    fun createBodyDef():BodyDef{
        var bodyDef = BodyDef()
        bodyDef.allowSleep = true
        return bodyDef
    }

}